package com.timoon.webcomponent.utility.info;

import java.util.List;

import org.apache.wicket.Page;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.timoon.sample.dao.model.Passage;

/**
 *<p>仿京东块标题</p>
 *<p>public</p>
 *<p>从info_sort获取八条记录code分别为[Info1Panel-n],n从零开始</p>
 *<p>Copyright:Copyright(c)2013</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */

public class Info1Panel extends Panel {
	
	@SpringBean(name="com.timoon.sample.service.InfoServiceImpl")
	private Info1Service service;
	
	private Class<?> targetPage;

	public Info1Panel(String id,Class<? extends Page> targetPage) {
		super(id);
		// TODO Auto-generated constructor stub
		
		this.targetPage=targetPage;
		
		renderPanel();
	}

	private void renderPanel() {
		// TODO Auto-generated method stub
		renderLabel();
		
		renderImg();
	}

	private void renderImg() {
		// TODO Auto-generated method stub
		
		
		add(new Image("wk_img",new PackageResourceReference(this.getClass(),"name.jpg")));
	}

	private void renderLabel() {
		// TODO Auto-generated method stub
		
		List<Passage> passages=this.service.getInfo();
		
		for(int i=0;i<8;i++){
			
			Passage passage=passages.get(i);
			
			String label=passage.getTitle();
			
			PageParameters pageParameters=new PageParameters();
			pageParameters.set("passage_id", passage.getId());
			
			BookmarkablePageLink link=new BookmarkablePageLink("wk_link_"+i, targetPage,pageParameters);
			add(link);
			
			link.add(new Label("wk_label_"+i,label));
		}
		
	}

}
